
clear all
cd "C:\Users\ot3\Documents\CRFertility\CensusMicrodata"

quietly infix                   ///
  int     year         1-4      ///
  long    sample       5-10     ///
  double  serial       11-18    ///
  byte    numprec      19-20    ///
  double  hhwt         21-30    ///
  byte    hhtype       31-31    ///
  double  cluster      32-44    ///
  byte    region       45-46    ///
  byte    statefip     47-48    ///
  byte    metro        49-49    ///
  double  strata       50-61    ///
  byte    gq           62-62    ///
  byte    farm         63-63    ///
  byte    ownershp     64-64    ///
  byte    ownershpd    65-66    ///
  byte    nfams        67-68    ///
  byte    nsubfam      69-69    ///
  byte    nmothers     70-70    ///
  byte    nfathers     71-71    ///
  byte    multgen      72-72    ///
  byte    multgend     73-74    ///
  int     pernum       75-78    ///
  double  perwt        79-88    ///
  byte    momloc       89-90    ///
  byte    stepmom      91-91    ///
  byte    nchild       92-92    ///
  byte    nchlt5       93-93    ///
  byte    nsibs        94-94    ///
  byte    eldch        95-96    ///
  byte    yngch        97-98    ///
  byte    relate       99-100   ///
  int     related      101-104  ///
  byte    sex          105-105  ///
  int     age          106-108  ///
  byte    marst        109-109  ///
  int     birthyr      110-113  ///
  byte    chborn       114-115  ///
  byte    race         116-116  ///
  int     raced        117-119  ///
  byte    hispan       120-120  ///
  int     hispand      121-123  ///
  int     bpl          124-126  ///
  long    bpld         127-131  ///
  byte    higrade      132-133  ///
  int     higraded     134-136  ///
  byte    educ         137-138  ///
  int     educd        139-141  ///
  byte    empstat      142-142  ///
  byte    empstatd     143-144  ///
  byte    labforce     145-145  ///
  int     occ          146-149  ///
  int     ind          150-153  ///
  long    inctot       154-160  ///
  long    ftotinc      161-167  ///
  long    incwage      168-173  ///
  long    incother     174-178  ///
  int     poverty      179-181  ///
  byte    occscore     182-183  ///
  int     migplac5     184-186  ///
  byte    chborn_mom   187-188  ///
  byte    chborn_mom2  189-190  ///
  using `"usa_00075.dat"'



*IPUMS extract is already restricted to females ages 14-44, non-Hispanic black or white

*basics
recode race (1=0)(2=1), gen(black)

g bornsouth=inlist(bpl, 1, 5, 12, 13, 22, 28, 37,  45, 47, 48, 51)
drop if inlist(statefip, 2,15) //AK & HI
g south= inlist(statefip, 1, 5, 12, 13, 22, 28, 37,  45, 47, 48, 51) 


*indicator of having child<1 in HH
recode yngch (0=1)(1/99=0), gen(newbirth) //IPUMS documentation: "Persons with no own-children present are coded 99"
keep if gq==1 & nfams==1  //drop group quarters and households with multiple unrelated families since there could be confusion re whose children are whose
replace newbirth=0 if chborn==0 //cannot be biological child (must be step/adopt) if woman never had children

*Birth order 
g highfert=nchild>=4

*education
recode educ (0=0)(1=2)(2=8)(3=9)(4=10)(5=11)(6=12)(7=13)(8=14)(9=15)(10=16)(11=18)
recode educ (0/8=1)(nonmiss=0), gen(higrade8)
recode educ (9/11=1)(nonmiss=0), gen(higrade11)
recode educ (12=1)(nonmiss=0), gen(hsgrad)
recode educ (13/18=1)(nonmiss=0), gen(collplus)

*farm
recode farm (1=0)(2=1)
g sharecrop=farm==1 & ownershp==2


*interactions
g y1969=year==1970
g blackXsouth=black*south
g blackXy1969=black*y1969
g southXy1969=south*y1969
g blackXsouthXy1969=black*south*y1969

g newbirthXy1969=newbirth*y1969
g newbirthXblack=newbirth*black
g newbirthXsouth=newbirth*south

g newbirthXblackXy1969=newbirth*black*y1969
g newbirthXsouthXy1969=newbirth*south*y1969
g newbirthXblackXsouth=newbirth*black*south

g newbirthXblackXsouthXy1969=newbirth*black*south*y1969


cd "C:\Users\ot3\Documents\CRFertility"
save census_selection_clean, replace












